home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / ZICXDTL.CPP < prev    next >
C/C++ Source or Header  |  1993-08-02  |  6KB  |  215 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    zn.cpp
  5. //   Title:    Zinc Window Template
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class ZI_CX_DETAIL.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <zi.hpp>
  41. #define USE_WIN_CX_DETAIL
  42. #if OS_DOS
  43. #include <zid.hpp>
  44. #elif OS_WINDOWS
  45. #include <ziw.hpp>
  46. #else
  47. #include <zio.hpp>
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //   Description:    Default constructor
  53. //    Parameters:
  54. //       Returns:    
  55. //----------------------------------------------------------------------------
  56. FN_M ZI_CX_DETAIL::ZI_CX_DETAIL(RZ4_CX rcx)
  57. : ZN_WINDOW("WIN_CX_DETAIL", ZN_LOAD_CENTER|ZN_LOAD_NO_SHOW)
  58. {
  59.     ZI_CX_DETAIL::Initialize(CL_INIT_CLASS);
  60.     cx = rcx;
  61.     Setup();
  62. }
  63.  
  64.  
  65. //----------------------------------------------------------------------------
  66. //   Description:    Destructor
  67. //    Parameters:
  68. //       Returns:    
  69. //----------------------------------------------------------------------------
  70. FN_M ZI_CX_DETAIL::~ZI_CX_DETAIL()
  71. {
  72.     ZI_CX_DETAIL::Destroy(FALSE);
  73.     Terminate();
  74. }
  75.  
  76.  
  77. //----------------------------------------------------------------------------
  78. //   Description:    Destroy object. Free any resources used by object.
  79. //                          Normally called by destructor.
  80. //                        Should allow multiple calls from various classes.
  81. //                        A class should almost always re-init its variables when 
  82. //                        it is destroyed to prevent accidents.
  83. //    Parameters:    fDestroyAll        Destroy parents also?
  84. //                                            Default is TRUE.
  85. //       Returns:    TRUE if successful.
  86. //----------------------------------------------------------------------------
  87. BOOL FN_M ZI_CX_DETAIL::Destroy(BOOL fDestroyAll)
  88. {
  89.     ZI_CX_DETAIL::Initialize(CL_INIT_CLASS_VARS);
  90.     if (fDestroyAll)                            // Destroy parent.
  91.         ZI_CX_DETAIL_PARENT::Destroy(fDestroyAll);
  92.     return TRUE;
  93. }
  94.  
  95.  
  96. //----------------------------------------------------------------------------
  97. //   Description:    
  98. //    Parameters:    
  99. //       Returns:    
  100. //----------------------------------------------------------------------------
  101. VOID FN_M ZI_CX_DETAIL::Format()
  102. {
  103.     CHAR szFormat[160];
  104.  
  105.     sprintf(szFormat, "%s, %s", cx.szCity, Z4_ST_FILE::Abbreviation(cx.state));
  106.     SetTitle(szFormat);
  107.  
  108.     SetString(FID(STR_CITY), cx.szCity);
  109.     SetString(FID(STR_STATE), Z4_ST_FILE::Full(cx.state));
  110.     
  111.     sprintf(szFormat, "%u", cx.cZip5);
  112.     SetString(FID(STR_ZIPS), szFormat);
  113.     if (cx.szPO[0])
  114.         {
  115.         SetString(FID(STR_NOTES),
  116.             "City name not valid for use on mail.");
  117.         sprintf(szFormat, "Preferred name is %s", cx.szPO);
  118.         SetString(FID(STR_PO), szFormat);
  119.         }
  120.     else
  121.         {
  122.         SetString(FID(STR_NOTES));
  123.         SetString(FID(STR_PO));
  124.         }
  125.     for (SIZET i = 0; i < cx.cZip5; ++i)
  126.         {
  127.         LONG lLow, lHigh;                        // Create list of ZIPs
  128.         CHAR szZip5[MAX_ZIP5+1];
  129.  
  130.         strb2a(cx.abZip5[i], MAX_ZIP5_BCD, szZip5, MAX_ZIP5, TRUE);
  131.         szZip5[MAX_ZIP5] = '\0';
  132.         lLow = lHigh = atol(szZip5);
  133.         for (; i + 1 < cx.cZip5; ++i)
  134.             {
  135.             strb2a(cx.abZip5[i+1], MAX_ZIP5_BCD, szZip5, MAX_ZIP5, TRUE);
  136.             szZip5[MAX_ZIP5] = '\0';
  137.             LONG lZip = atol(szZip5);
  138.             if (lHigh + 1 == lZip)
  139.                 lHigh = lZip;
  140.             else
  141.                 break;
  142.             }
  143.         if (lLow == lHigh)
  144.             sprintf(szFormat, "%05ld", lLow);
  145.         else
  146.             sprintf(szFormat, "%05ld - %05ld", lLow, lHigh);
  147.         SetVtList(FID(LB_ZIP5), szFormat);
  148.         }
  149.     return ;
  150. }
  151.  
  152.  
  153. //----------------------------------------------------------------------------
  154. //   Description:    Initialize object. 
  155. //                          Normally called by constructor.
  156. //                        Should allow multiple calls from various classes.
  157. //    Parameters:    sInit        Initialization code. May be one of the following:
  158. //                                        CL_INIT_CLASS            Reset class variables and
  159. //                                                                    and dynamic allocations for
  160. //                                                                    this class only.
  161. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  162. //                                                                    this class only.
  163. //                                        CL_INIT_VARS            Reset class variables for
  164. //                                                                    this class only.
  165. //                                        CL_INIT_ALL                Initialize class and all 
  166. //                                                                    parent class, including
  167. //                                                                    dynamic memory allocation.
  168. //                                    Default is CL_INIT_ALL
  169. //       Returns:    TRUE if successful.
  170. //----------------------------------------------------------------------------
  171. BOOL FN_M ZI_CX_DETAIL::Initialize(SHORT sInit)
  172. {
  173.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  174.         ZI_CX_DETAIL_PARENT::Initialize(sInit);
  175.  
  176.     if (sInit == CL_INIT_CLASS_VARS || sInit == CL_INIT_VARS)
  177.         return TRUE;
  178.  
  179.     return TRUE;
  180. }
  181.  
  182.  
  183. //----------------------------------------------------------------------------
  184. //   Description:    Event monitor function.
  185. //    Parameters:    msg        Event code
  186. //                        pv1            Data pointer 1
  187. //                        pv2            Data pointer 2
  188. //       Returns:    Event code
  189. //----------------------------------------------------------------------------
  190. ZN_MSG FN_M ZI_CX_DETAIL::User(ZN_MSG msg, PVOID, PVOID)
  191. {
  192.     switch (msg)
  193.         {
  194.         case ZN_MSG_INIT:
  195.             Format();
  196.             return msg;
  197.  
  198.         case ZN_MSG_TERMINATE:
  199.             return msg;
  200.         }
  201.     if (IsError())                                // Error condition
  202.         return msg;
  203.     switch (msg)
  204.         {
  205.         case BUTTON_OK:
  206.             Close();
  207.             break;
  208.         }
  209.     return msg;
  210. }
  211. //----------------------------------------------------------------------------
  212. //------------------------------- End of File --------------------------------
  213. //----------------------------------------------------------------------------
  214.  
  215.